<template>
  <div class="app-container">
    <el-form ref="scholarshipForm" :model="scholarshipData" label-width="120px">
      <el-form-item label="奖学金名称">
        <el-input v-model="scholarshipData.scholarshipName" placeholder="请输入奖学金名称"></el-input>
      </el-form-item>
      <el-form-item label="类型">
        <el-input-number v-model="scholarshipData.type" :min="0" placeholder="请输入类型"></el-input-number>
      </el-form-item>
      <el-form-item label="获奖人数比例">
        <el-input-number v-model="scholarshipData.ratio" :min="0" :max="100" placeholder="请输入获奖人数比例" append>%</el-input-number>
      </el-form-item>
      <el-form-item label="状态">
        <el-radio-group v-model="scholarshipData.status">
          <el-radio :label="1">正常</el-radio>
          <el-radio :label="2">禁用</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">提交</el-button>
        <!-- <el-button @click="resetForm">重置</el-button> -->
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { insertScholarship } from "@/api/scholarship";
export default {
  props: {
    isEdit: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      scholarshipData: {
        scholarshipName: "",
        type: 1,
        ratio: 0,
        status: 1
      },
    };
  },
  methods: {
    submitForm() {
      this.$refs.scholarshipForm.validate((valid) => {
        if (valid) {
          // 在这里处理表单提交逻辑，例如发送请求到后端API
          console.log("提交的奖学金数据:", this.scholarshipData);
          // 以下代码示例，实际应用中需要替换为API调用
          // this.saveScholarship(this.scholarshipData);
          insertScholarship(this.scholarshipData).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: "新增成功",
                type: "success",
              });
            } else {
              this.$message({
                message: res.msg ,
                type: "error",
              });
            }
            console.log(res);

            this.scholarshipData.scholarshipName = "";
          });
        } else {
          
          console.log("表单验证失败");
          return false;
        }
      });
    },
    resetForm() {
      this.$refs.scholarshipForm.resetFields();
    },
  },
};
</script>